package com.wanlian.router;

import com.wanlian.router.bean.User;
import com.wanlian.router.storage.AppData;
import com.wanlian.router.storage.UserData;

/**
 * Created by Hyu on 2018/9/12.
 * Email: fvaryu@163.com
 */
public class GlobalInfo {
    private User mUser;
    private long mUserId;

    private static final GlobalInfo ourInstance = new GlobalInfo();

    public static GlobalInfo getInstance() {
        return ourInstance;
    }

    private GlobalInfo() {
    }

    public User getUser() {
        return mUser;
    }

    public void setUser(User user) {
        mUser = user;
        if (mUser != null) {
            this.mUserId = user.getId();
        }
    }

    public long getUserId() {
        return mUserId;
    }

    public UserData getUserData() {
        return UserData.DEFAULT;
    }

    public AppData getAppData() {
        return AppData.DEFAULT;
    }

    public void logout() {
        mUserId = 0;
        mUser = null;
        getUserData().clean();
    }

    public boolean isLogin() {
        return UserData.DEFAULT.getUserId() > 0;
    }
}
